﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace PluginInterFace.DAL
{
    public class ssq
    {
        public ssq()
        {
            //初始化
        }

        public DataSet GetList(string strWhere)
        {
            AccessHelp AH = new AccessHelp();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM ssq ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" ORDER BY 期号 DESC");
            return AH.GetDataSet(strSql.ToString());
        }

        public DataSet GetList(string strWhere, int sRecord, int mRecord)
        {
            AccessHelp AH = new AccessHelp();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM ssq ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" ORDER BY 期号 DESC");
            return AH.GetDataSet(strSql.ToString(), sRecord, mRecord);
        }

        public bool AddData(Model.ssq[] mss)
        {
            AccessHelp AH = new AccessHelp();
            StringBuilder strSql = new StringBuilder();
            int i;
            for (i = 0; i < mss.Length; i++)
            {
                if (mss[i].日期 == "" || mss[i].日期 == " ")
                    continue;
                strSql.Remove(0, strSql.Length);
                strSql.Append("INSERT INTO ssq ");
                strSql.Append("VALUES ('");
                strSql.Append(mss[i].日期 + "',");
                strSql.Append(mss[i].期号.ToString() + ",");
                strSql.Append(mss[i].红1.ToString() + ",");
                strSql.Append(mss[i].红2.ToString() + ",");
                strSql.Append(mss[i].红3.ToString() + ",");
                strSql.Append(mss[i].红4.ToString() + ",");
                strSql.Append(mss[i].红5.ToString() + ",");
                strSql.Append(mss[i].红6.ToString() + ",");
                strSql.Append(mss[i].蓝.ToString() + ",");
                strSql.Append(mss[i].销售额.ToString() + ",");
                strSql.Append(mss[i].一等奖.ToString() + ",");
                strSql.Append(mss[i].二等奖.ToString() + ")");
                if (!AH.ExecuteDataBase(strSql.ToString()))
                    return false;
            }
            return true;
        }

        public bool UpData(Model.ssq mss)
        {
            AccessHelp AH = new AccessHelp();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE Person SET ");
            strSql.Append("日期='" + mss.日期 + "' ");
            strSql.Append("红1=" + mss.红1 + " ");
            strSql.Append("红2=" + mss.红2 + " ");
            strSql.Append("红3=" + mss.红3 + " ");
            strSql.Append("红4=" + mss.红4 + " ");
            strSql.Append("红5=" + mss.红5 + " ");
            strSql.Append("红6=" + mss.红6 + " ");
            strSql.Append("蓝=" + mss.蓝 + " ");
            strSql.Append("销售额=" + mss.销售额 + " ");
            strSql.Append("一等奖=" + mss.一等奖 + " ");
            strSql.Append("二等奖=" + mss.二等奖 + " ");
            strSql.Append("WHERE 期号=" + mss.期号);
            return AH.ExecuteDataBase(strSql.ToString());
        }

        public bool DelData(int 期号)
        {
            AccessHelp AH = new AccessHelp();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("DELETE FROM ssq WHERE 期号=" + 期号);
            return AH.ExecuteDataBase(strSql.ToString());
        }

        public bool ExistsData(int 期号)
        {
            AccessHelp AH = new AccessHelp();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ssq WHERE 期号=" + 期号.ToString());
            if (AH.GetScalar(strSql.ToString()) == null)
                return false;//不存在
            else
                return true;//存在
        }

        public bool ExistsData(int 红1, int 红2, int 红3, int 红4, int 红5, int 红6, int 蓝)
        {
            AccessHelp AH = new AccessHelp();
            string strSql;
            strSql = string.Format("SELECT * FROM ssq WHERE 红1={0} AND 红2={1} AND 红3={2} AND 红4={3} AND 红5={4} AND 红6={5} AND 蓝={6}", 红1, 红2, 红3, 红4, 红5, 红6, 蓝);
            if (AH.GetScalar(strSql) == null)
                return false;//不存在
            else
                return true;//存在
        }

        public bool CopyData(string dfile)
        {
            AccessHelp AH = new AccessHelp();
            string strSql;
            strSql = string.Format("insert into ssq select * from {0}.ssq", dfile);
            return AH.ExecuteDataBase(strSql);
        }
    }
}
